package com.djsearch.widget;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

public class DragableCircle extends View {

	private int CircleCount;
	private int mCurrentScreen;
	Paint circlePaint;
	Paint bgPaint;

	public DragableCircle(Context context) {
		super(context);
		circlePaint = new Paint();
		circlePaint.setColor(0xFFFFFFFF);
		circlePaint.setAntiAlias(true);
		bgPaint = new Paint();
		bgPaint.setColor(0x00000000);
		bgPaint.setAntiAlias(true);
		bgPaint.setAlpha(100);
		// circlePaint.setShadowLayer(2, 0, 0, 0xff000000);

		this.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.FILL_PARENT));
	}
	
	public DragableCircle(Context context,AttributeSet attr) {
		super(context,attr);
		circlePaint = new Paint();
		circlePaint.setColor(0xFFFFFFFF);
		circlePaint.setAntiAlias(true);
		bgPaint = new Paint();
		bgPaint.setColor(0x00000000);
		bgPaint.setAntiAlias(true);
		bgPaint.setAlpha(100);
		// circlePaint.setShadowLayer(2, 0, 0, 0xff000000);

		this.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.FILL_PARENT));
	}

	public void SetCircleCount(int cnt) {
		CircleCount = cnt;
	}

	public void SetCurrentScreen(int screen) {
		mCurrentScreen = screen;
	}

	@Override
	protected void dispatchDraw(Canvas canvas) {
		if (CircleCount <= 1) return;
		// 开始画底下的那些圆圈
		// 圆圈是7px，间隔是10px
		int CirclesWidth = (CircleCount - 1) * 14;
		int width = getWidth();
		int height = getHeight();
		int x = (width - CirclesWidth) / 2;
		int y = height - 10;
		//画背景
		RectF rect = new RectF();
		rect.top = y - 10;
		rect.bottom = y + 10;
		rect.left = x - 10;
		rect.right = x + CirclesWidth + 10;
		canvas.drawRoundRect(rect, 8, 8, bgPaint);
		
		for (int i = 0; i < CircleCount; i++) {
			if (i == mCurrentScreen) {
				circlePaint.setAlpha(255);
			} else {
				circlePaint.setAlpha(100);
			}
			canvas.drawCircle(x, y, 4, circlePaint);
			x += 14;
		}
	}
}
